/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
  ListNode* deleteNode(ListNode* head, int val) {

    ListNode *dummyHead = new ListNode(-1, head);
    ListNode *pre = dummyHead;
    ListNode *p = dummyHead->next;

    while(p != nullptr){
      if(p->val == val){
        pre->next = p->next;
        // 题目特别说明：若使用 C 或 C++ 语言，你不需要 free 或 delete 被删除的节点
        // delete p;
        p = nullptr;
        break;
      }
      p = p->next;
      pre = pre->next;
    }

    return dummyHead->next;

  }
};